
$servicesToControl = "ContentFeedProcessing","CacheDeletionService","ContentProcessing","HistoryProcessing","DEProcessing"

function usage(){
	Write-Warning "### USAGE: controlICNETservices.ps1 <START|STOP>" 
}

if($args.length -ne 1){
	Write-Host "This script must include a control argument [START, STOP]" -foreground "red";
	usage;
	exit;
}

$controlProvided = $args[0]
$acceptableControls = "START", "STOP"
if($acceptableControls -notcontains $args[0]){		
		Write-Host "$controlProvided is not a valid control argument." -foreground "red";
		Write-Host "This script must include a control argument [START, STOP]" -foreground "red";
		usage;
		exit;
}

$verb = "Starting"
$ptVerb = "started"
if($controlProvided -eq "STOP"){
	$verb = "Stopping"
	$ptVerb = "stopped"
} 

Write-Host "############# IC.NET SERVICES [$controlProvided]#############"
foreach ($service in $servicesToControl){
	Write-Host "$verb $service..."
	$cmdOutput = & net $controlProvided $service 2>&1
	$hasError = $FALSE
	if($cmdOutput -like '*HELPMSG*'){
		$hasError = $TRUE
	}	
	if($hasError){
		Write-Host ">>> OOPS! Something went awry! <<<" -foreground "red"
		Write-Host $error[0] -foreground "red"
	}else{
		Write-Host ">>> $service successfully $ptVerb <<<" -foreground "green"
	}
}
